﻿using System;
using Ease.EaseDialog.Runtime.Data;
using Ease.EaseDialog.Runtime.UI;
using Ease.EaseNode.Runtime;
using Ease.EaseNode.Runtime.Param;

namespace Ease.EaseDialog.Runtime.DataAgent
{
    public class BaseDialogDataAgent : IEaseNodeAgent
    {
        public event Action<BaseChangeParam> OnValueChangeEvent;
        public IEaseNodeData Data { get; set; }

        public BaseDialogDataAgent(IEaseNodeData data)
        {
            Data = data;
            OnStateChange(1);
        }

        public void Start(Action overCallback)
        {
            OnStateChange(2);
            UIDialog.Instance.SetData(Data as BaseDialogData, () =>
            {
                OnStateChange(4);
                overCallback?.Invoke();
            });
        }

        private void OnStateChange(int state)
        {
            OnValueChangeEvent?.Invoke(new StateChangeParam() { newState = (NodeState)state });
        }
    }
}